<div class="nav">
    <a href="{:U('index')}">配送方式列表</a>
    <a href="{:U('add')}">添加配送方式</a>
    <a class="sel" href="#">地区运费配置</a>
</div>
<div class="search">
    <label><input type="checkbox" name="open_default" id="open_default" <if condition="$delivery.open_default eq 1">checked="checked"</if> value="1" /> 未设置地区采用默认运费</label> &nbsp;<input type="button" onclick="set_open_default()" class="btn1" value="保存" /> <label class="msg">注意：如果不开启此项，那么未设置的地区将无法送达！</label>
</div>
<div class="search" style="margin-top:12px;">
    <form method="post" action="{:U('area_add')}" onSubmit="return checkform()" >
         <input type="hidden" name="delivery_id" id="delivery_id" value="{$delivery_id}" />
    添加地区：
   <span id="span_province">
        <select name="province" id="province" class="sel1">
            <option value="">选择省份</option>
            <foreach name="province" item="prov">
                <option value="{$prov.province}">{$prov.province}</option>
            </foreach>
        </select>
   </span> &nbsp;
    <span id="span_city"></span> &nbsp;
    首重费用：<input type="text" style="width:40px" name="first_price" id="first_price" value="{$delivery.first_price}" /> 元
    续重费用：<input type="text" style="width:40px" name="second_price" id="second_price" value="{$delivery.second_price}" /> 元
    <input type="submit" class="btn1" value="添加"/>
    </form>
</div>
<div class="list">
    <table class="table_list">
        <thead>
            <tr>
                <td>省份</td>
                <td>城市</td>
                <td width="100px">首重价格</td>
                <td width="100px">续重价格</td>
                <td width="60px">启用</td>
                <td width="120px">操作</td>
            </tr>
        </thead>
        <tbody> 
        <foreach name="list" item="list">
            <tr>
            <td>{$list.province}</td>
            <td>{$list.city}</td>
            <td class="edit_input" attr_t="first_price" attr_id="{$list.id}">{$list.first_price}</td>
            <td class="edit_input" attr_t="second_price" attr_id="{$list.id}">{$list.second_price}</td>
            <td class="edit_toggle" attr_t="is_enable" attr_id="{$list.id}">{$list.is_enable}</td>
            <td>
                <a class="btn_a2" href="{:U('area_del',Array('delivery_id'=>$list['delivery_id'],'id'=>$list['id']))}" onclick="return confirm('确定删除吗？')">删除</a></td>
            </tr>
        </foreach>
        </tbody>
        <tfoot>
            <tr><td colspan="6"><div class="page">{$page}</div></td></tr>
        </tfoot>
    </table>
</div>
<script type="text/javascript">
    //添加判断
     function checkform() {
         var province = $.trim($("#province").val());
         var city = $.trim($("#city").val());
         var first_price = $.trim($("#first_price").val());
         var second_price = $.trim($("#second_price").val());
         if(province == '') {
             alert("请选择省份");
             $("#province").focus();
             return false;
         } else if(city == '') {
             alert("请选择城市");
             $("#city").focus();
             return false;
         }else if(first_price == '') {
             alert("请填写首重价格");
             $("#first_price").focus();
             return false;
         }else if(second_price == '') {
             alert("请填写续重价格");
             $("#second_price").focus();
             return false;
         }
         
     }
    
    //用户地区选择
     $("#province").change(function() {
            change_province();
     });

    function change_province() {
        var province = $("#province").val();
        $("#span_city").load("{:U('Address/city_sel2')}?province=" + encodeURI(province) + "&city=");
        $("#span_area").html("");
    }
    
    //设置默认地区运费
    function set_open_default() {
        var open_default = 0;
        if($("#open_default").is(':checked')) {
            open_default = 1;
        }
        var delivery_id = $("#delivery_id").val();
        $.ajax({
            url:"{:U('set_open_default')}",
            type:'POST',
            cache:false,
            data:{delivery_id:delivery_id,open_default:open_default},
            success:function(val) {
                alert(val);
            }
        })
        
    }
    
</script>

